Skip to content

Role and Permission provisioning for user #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MarcusGoldschmidt
Copy link

@MarcusGoldschmidt MarcusGoldschmidt commented Apr 30, 2025

Increase bato-sdl

Add database user provisioning

Provisioning for role and permission

if the user does not exist in the database, create with the current server principal

@MarcusGoldschmidt MarcusGoldschmidt changed the title Goldschmidt/provisioning Role and Permission provisioning for user May 1, 2025
@laurenleach laurenleach self-requested a review May 1, 2025 22:16
@btipling btipling force-pushed the goldschmidt/provisioning branch from 40627a0 to 68b456a Compare May 3, 2025 21:29
Copy link
Contributor

@btipling btipling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments about sql injection concerns, but lgtm

return nil, nil, fmt.Errorf("unexpected database id: %s", splitId[1])
}

permission := splitId[2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe we want a helper function for extracting parts of an id

}

dbName := splitId[1]
roleId := splitId[2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe helper function?

return fmt.Errorf("invalid characters in dbName or user")
}

command := fmt.Sprintf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is this sprintf safe? should we escape? from the perspective of just this function, with encapsulation in mind where do not assume we know who called this function and with what arguments, we're concatenating unknown unescaped strings into a query against someone's prod database and we don't have any idea of what these strings are

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQL Server’s limitation, no driver alows us to bind table names, permissions or db.

Like normal command SELECT * FROM user WHERE Id = @p1 we can't use this for grant

Ex: "GRANT @p1 ON DATABASE::[@p2] TO [@p3];"

return fmt.Errorf("invalid characters in dbName or user")
}

command := fmt.Sprintf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sprintf

l := ctxzap.Extract(ctx)
l.Debug("getting database role", zap.String("id", id), zap.String("dbName", dbName))

if strings.ContainsAny(dbName, "[]\"';") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this enough escaping?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants